package com.yyn.Learning.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yyn.Learning.entity.EduComment;
import com.yyn.Learning.mapper.EduCommentMapper;
import com.yyn.Learning.service.EduCommentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 评论 服务实现类
 * </p>
 *
 * @author yyn
 * @since 2023-01-10
 */
@Service
public class EduCommentServiceImpl extends ServiceImpl<EduCommentMapper, EduComment> implements EduCommentService {
@Autowired
private EduCommentMapper eduCommentMapper;
    @Override
    public void saveComment(HashMap<String,String> memberInfo, EduComment eduComment) {
//        取HashMap 数据
        String  id = memberInfo.get("id");
        String nickname = memberInfo.get("nickname");
        String avatar = memberInfo.get("avatar");

        eduComment.setContent(eduComment.getContent());
        eduComment.setTeacherId(eduComment.getTeacherId());
        eduComment.setCourseId(eduComment.getCourseId());
        eduComment.setMemberId(id);
        eduComment.setAvatar(avatar);
        eduComment.setNickname(nickname);
        this.save(eduComment);

    }

    @Override
    public List<EduComment> getComment(String courseId, String teacherId) {
        LambdaQueryWrapper<EduComment> eduCommentLambdaQueryWrapper = new LambdaQueryWrapper<>();
        eduCommentLambdaQueryWrapper.eq(EduComment::getTeacherId,teacherId);
        eduCommentLambdaQueryWrapper.eq(EduComment::getCourseId,courseId);
        eduCommentLambdaQueryWrapper.orderByDesc(EduComment::getGmtCreate);
        List<EduComment> list = this.list(eduCommentLambdaQueryWrapper);
        return list;
    }
}
